home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Sources / Panes / PedPaneTE.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  4.6 KB  |  291 lines

  1. /*    ============
  2.  *    PedPaneTE.cc
  3.  *    ============
  4.  */
  5.  
  6. #include "PedestalDebugging.h"
  7.  
  8. #include <Fonts.h>
  9. #include <TextEdit.h>
  10. #include <Windows.h>
  11.  
  12. #include "PedPaneTE.hh"
  13.  
  14. #include "Ped1AppProcess.hh"
  15. #include "PedApplication.hh"
  16. #include "PedView.hh"
  17.  
  18. PedPaneTE::PedPaneTE(PedView &inSuperView)
  19. : PedPane(inSuperView), macTE(NULL)
  20. {
  21. }
  22.  
  23. PedPaneTE::~PedPaneTE()
  24. {
  25. }
  26.  
  27. void
  28. PedPaneTE::GetBounds(Rect &outBounds)
  29. {
  30.     outBounds = mBounds;
  31.     if (macTE) {
  32.         short textHeight;
  33.         textHeight = (*macTE)->nLines * (*macTE)->lineHeight;
  34.         outBounds.bottom = outBounds.top + 4 + textHeight + 4;
  35.     }
  36. }
  37.  
  38. // FIXME:  This is redundant
  39. void
  40. PedPaneTE::SetBounds(const Rect &inBounds)
  41. {
  42.     mBounds = inBounds;
  43. }
  44.  
  45. void
  46. PedPaneTE::GetScrollPos(Point &outPos)
  47. {
  48.     if (macTE) {
  49.         outPos.h = (*macTE)->viewRect.left - (*macTE)->destRect.left;
  50.         outPos.v = (*macTE)->viewRect.top - (*macTE)->destRect.top;
  51.     } else {
  52.         ::SetPt(&outPos, 0, 0);
  53.     }
  54. }
  55.  
  56.  
  57. enum {kPedMsgNone, kPedMsgScroll, kPedMsgNotifyScrolledTo};
  58.  
  59. void
  60. PedPaneTE::NotifyIfScrolled(Point inOldPos)
  61. {
  62.     Point newPos;
  63.     
  64.     GetScrollPos(newPos);
  65.     if (inOldPos.v != newPos.v || inOldPos.h != newPos.h) {
  66.         mSuperView.Message(kPedMsgNotifyScrolledTo, &newPos);
  67.     }
  68. }
  69.  
  70.  
  71. void
  72. PedPaneTE::Init()
  73. {
  74. }
  75.  
  76. void
  77. PedPaneTE::Open()
  78. {
  79.     Rect textRect;
  80.     
  81.     PedPane::Open();
  82.     
  83.     if (macTE) return;
  84.     
  85.     //::SetPort(macWindow);
  86.     ::TextFont(kFontIDMonaco);
  87.     ::TextSize(9);
  88.     //mSuperView.GetFrame(textRect);
  89.     textRect = mBounds;
  90.     ::InsetRect(&textRect, 4, 4);
  91.     macTE = ::TENew(&textRect, &textRect);
  92.     if (!macTE) throw;
  93.     ::TEAutoView(true, macTE); // enable auto-scrolling
  94. }
  95.  
  96. void
  97. PedPaneTE::Close()
  98. {
  99.     if (macTE) {
  100.         ::TEDispose(macTE);
  101.         macTE = NULL;
  102.     }
  103.     
  104.     PedPane::Close();
  105. }
  106.  
  107. void
  108. PedPaneTE::Activate()
  109. {
  110.     if (macTE)
  111.         ::TEActivate(macTE);
  112.     
  113. }
  114.  
  115. void
  116. PedPaneTE::Deactivate()
  117. {
  118.     if (macTE)
  119.         ::TEDeactivate(macTE);
  120. }
  121.  
  122. void
  123. PedPaneTE::Resize(short inWidth, short inHeight)
  124. {
  125.     PedPane::Resize(inWidth, inHeight);
  126.     
  127.     if (!macTE) return;
  128.     
  129.     Point offset;
  130.     mSuperView.GetWindowToLocalOffset(offset);
  131.     
  132.     Rect textRect = mBounds;
  133.     ::InsetRect(&textRect, 4, 4);
  134.     ::OffsetRect(&textRect, offset.h, offset.v);
  135.     (*macTE)->destRect = textRect;
  136.     textRect = mAperture;
  137.     ::InsetRect(&textRect, 4, 4);
  138.     (*macTE)->viewRect = textRect;
  139.     ::TECalText(macTE);
  140.     ::InvalRect(&mBounds);
  141. }
  142.  
  143. void
  144. PedPaneTE::Scroll(short inH, short inV, bool inUpdate)
  145. {
  146.     // FIXME
  147.     ::TEPinScroll(-inH, -inV, macTE);
  148. }
  149.  
  150. void
  151. PedPaneTE::Draw()
  152. {
  153.     if (!macTE) return;
  154.     
  155.     Rect frame;
  156.     mSuperView.GetFrame(frame);
  157.     
  158.     ::EraseRect(&frame);
  159.     ::TEUpdate(&frame, macTE);
  160. }
  161.  
  162. void
  163. PedPaneTE::DispatchNullEvent(EventRecord &inEvent)
  164. {
  165.     ::GlobalToLocal(&inEvent.where);
  166.     if (::PtInRect(inEvent.where, &mBounds)) {
  167.         CursHandle cursIBeam = ::GetCursor(iBeamCursor);
  168.         ThrowIfNULL_(cursIBeam);
  169.         ::SetCursor(*cursIBeam);
  170.     } else
  171.         ::SetCursor(&qd.arrow);
  172.     if (macTE)
  173.         ::TEIdle(macTE);
  174. }
  175.  
  176.  
  177. void
  178. PedPaneTE::DispatchClickEvent(EventRecord &inEvent)
  179. {
  180.     if (macTE == NULL)
  181.         return;
  182.     
  183.     Point oldPos;
  184.     GetScrollPos(oldPos);
  185.     
  186.     //::SetPort(macWindow);
  187.     ::GlobalToLocal(&inEvent.where);
  188.     ::TEClick(inEvent.where, inEvent.modifiers & shiftKey != 0, macTE);
  189.     
  190.     NotifyIfScrolled(oldPos);
  191. }
  192.  
  193. void
  194. PedPaneTE::DispatchKey(EventRecord &inEvent)
  195. {
  196. //    if (mResponder) {
  197. //        char c = inEvent.message & charCodeMask;
  198. //        short code = (inEvent.message & keyCodeMask) >> 8;
  199. //        mResponder->RespondToKey(c, code);
  200. //    }
  201. }
  202.  
  203. void
  204. PedPaneTE::DoKey(char inChar)
  205. {
  206.     if (macTE) {
  207.         switch (inChar) {
  208.             case '\x00':
  209.                 break;
  210.             default:
  211.                 break;
  212.         }
  213.         
  214.         Point oldPos;
  215.         GetScrollPos(oldPos);
  216.         
  217.         ::TEKey(inChar, macTE);
  218.         
  219.         NotifyIfScrolled(oldPos);
  220.     }
  221. }
  222.  
  223. void
  224. PedPaneTE::GetSelection(long *inStart, long *inEnd)
  225. {
  226.     if (!macTE) {*inStart = *inEnd = 0; return;}
  227.     
  228.     *inStart = (*macTE)->selStart;
  229.     *inEnd = (*macTE)->selEnd;
  230. }
  231.  
  232. void
  233. PedPaneTE::SetSelection(short inStart, short inEnd)
  234. {
  235.     if (!macTE) return;
  236.     
  237.     Point oldPos;
  238.     GetScrollPos(oldPos);
  239.     
  240.     ::TESetSelect(inStart, inEnd, macTE);
  241.     
  242.     NotifyIfScrolled(oldPos);
  243. }
  244.  
  245. long
  246. PedPaneTE::AppendChars(char *buffer, long n)
  247. {
  248.     if (!macTE) return 0;
  249.     
  250.     ::SetHandleSize((*macTE)->hText, (*macTE)->teLength + n);
  251.     ThrowIfOSErr_(::MemError());
  252.     ::BlockMoveData(buffer, *(*macTE)->hText + (*macTE)->teLength, n);
  253.     (*macTE)->teLength += n;
  254.     ::TECalText(macTE);
  255.     mSuperView.Refresh();
  256.     
  257.     // We don't call NotifyIfScrolled() because we don't scroll at all.
  258.     // Our caller may call SetSelection() afterward, though,
  259.     // which case is handled already.
  260.     
  261.     return n;
  262. }
  263.  
  264. void
  265. PedPaneTE::Cut()
  266. {
  267.     if (macTE)
  268.         ::TECut(macTE);
  269. }
  270.  
  271. void
  272. PedPaneTE::Copy()
  273. {
  274.     if (macTE)
  275.         ::TECopy(macTE);
  276. }
  277.  
  278. void
  279. PedPaneTE::Paste()
  280. {
  281.     if (macTE)
  282.         ::TEPaste(macTE);
  283. }
  284.  
  285. void
  286. PedPaneTE::Clear()
  287. {
  288.     if (macTE)
  289.         ::TEDelete(macTE);
  290. }
  291.